package com.java并发编程.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CallableTest implements Callable<String>{
	
	private int a;
	
	public CallableTest(int a) {
		super();
		this.a = a;
	}

	@Override
	public String call() throws Exception {
		Thread.sleep(5000);
		return "a为： " + a;
	}
	
	public static void main(String[] args) {
		try {
			CallableTest cT = new CallableTest(1000);
			//注：有界队列：core--->队列--->max
			//注：无界队列：core--->队列，max无意义
			ThreadPoolExecutor pool = 
					new ThreadPoolExecutor(2, 5, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue(5));
			Future<String> submit = pool.submit(cT);
			System.out.println("get前");
			String string = submit.get();//get方法是阻塞的
			System.out.println("get后");
			
			System.out.println(string);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

}
